package com.antler.smt.portal.controller;

import com.antler.smt.enums.ResultCodeEnum;
import com.antler.smt.portal.annotation.OperateCut;
import com.antler.smt.request.admin.GetProposalListReq;
import com.antler.smt.response.base.Result;
import com.antler.smt.service.portal.ProposalService;
import com.antler.smt.utils.LogUtil;
import com.antler.smt.validate.DataValidator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 意见与反馈接口
 *
 * @author zhangyi
 * @date 2018/3/21 12:58
 */
@RestController
@RequestMapping(value = "/proposal")
@Api(description = "意见与反馈接口")
public class ProposalController extends BaseController{

  /**
   * 日志
   */
  private static Logger log = LogUtil.get();

  @Resource
  private ProposalService proposalService;

  /**
   * 写入意见与反馈信息
   *
   * @param request 请求实体
   * @return Result实体
   */
  @PostMapping("/insertProposal")
  @ApiOperation(value = "写入意见与反馈信息", httpMethod = "POST")
  @OperateCut(operationContent = "写入意见与反馈信息")
  public Result<ResultCodeEnum> insertProposal(@RequestBody GetProposalListReq request) {

    DataValidator.isNull(request,"请求意见反馈实体不能为空！");
    DataValidator.isBlank(request.getContent(),"请求意见反馈内容不能为空！");

    Result result = null;
      if(currentMember != null) {
        result = proposalService.insertProposalByMember(request,currentMember.getId());
      }else{
        result = proposalService.insertProposalRand(request);
      }
    return result;
  }
}
